const jwt = require('jsonwebtoken')
const tool = {
    getRes: (res, code, msg, data = {}) => res.json({ code, msg, data: { ...data } }),
    getToken: {
        encrypt: (data = {}, secret, time) => jwt.sign({ data }, secret, { expiresIn: time }),
        decrypt: (token, secret) => {
            try {
                jwt.verify(token, secret)
                return true
            } catch (e) {
                return false
            }
        }
    }

}
module.exports = tool